#include "base/core/com_define.h"
#include "base/core/mem_tracker.h"

template<class TYPE> inline
ObjectPool<TYPE>::ObjectPool(uint32_t count_in_block,
                             bool auto_free /*= true*/) 
	:ChunkPool(0, sizeof(TYPE), count_in_block, auto_free) {}

template<class TYPE> inline ObjectPool<TYPE>::~ObjectPool(void)
{}

template<class TYPE> inline TYPE* ObjectPool<TYPE>::Alloc()
{
	TYPE* obj = (TYPE*)AllocChunk();
	if (obj) 
	{
		new (obj) TYPE();
	}
	return obj;
}

template<class TYPE> inline bool ObjectPool<TYPE>::Free(TYPE* obj) 
{
	MMO_ASSERT(obj);
	obj->~TYPE();
	return FreeChunk(obj);
}

template<class TYPE> inline TYPE* ObjectPool<TYPE>::AllocTrack(const char* file,
															   const char* func,
															   uint32_t line) 
{
	TYPE* obj = (TYPE*)AllocChunk();
	if (obj) 
	{
		new (obj) TYPE();
		g_MemTracker().TrackMalloc(obj, file, func, line);
	}
	return obj;
}

template<class TYPE> inline bool ObjectPool<TYPE>::FreeTrack(TYPE* obj)
{
	MMO_ASSERT(obj);
	obj->~TYPE();
	g_MemTracker().TrackFree(obj);
	return FreeChunk(obj);
}
